<%@ Page Culture="en-US" UICulture="en-US" Language="C#" Explicit="true" Debug="false"%>

<%@Import Namespace="System" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<%@Import Namespace="System.Data.OleDb" %>
<%@Import Namespace="System.Globalization"%>
<%@Import Namespace="System.Threading"%>


<Script LANGUAGE="C#" runat="server">

string strPK_ID;
string strPageload;


    void Page_Load() 
    {
          if (!IsPostBack)                //initially coming into this web page from another external web page
          {
             strPageload = "setFocus()";        //so as to focus on particular field on the page when loading
     
             control.Value = Convert.ToString(Request.QueryString["textbox"]);
             caldatelabel.Text = Convert.ToString(Request.QueryString["textlabel"]);

             GetYearList();
             GetMonthList();
          } 
          else     //when running post back within page 
          {   
            //strPageload = "";
            //Response.Write(("Doing Postback within page " + "<br>\""));
            strPageload = "setPostBack()";
           }
       
     }


    private void GetYearList() 
    {
        int indx;
        for (indx = 1900; (indx <= 2050); indx++) {
            ddlYear.Items.Add(new ListItem(indx.ToString(), indx.ToString()));
        }
        // Go to Current Year
        ddlYear.Items.FindByText(DateTime.Now.ToString("yyyy")).Selected = true;
    }


    private void GetMonthList() 
    {
        DataTable dt;
        DataRow dr;
        string strStatus;
        string strstatusread;

        // create a temporary DataTable for Month dropdownlist
        dt = new DataTable();
        dt.Columns.Add(new DataColumn("month", typeof(string)));
        dt.Columns.Add(new DataColumn("month_number", typeof(string)));

        dr = dt.NewRow();
        strStatus = "January";
        dr[0] = strStatus;
        dr[1] = "01";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "February";
        dr[0] = strStatus;
        dr[1] = "02";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "March";
        dr[0] = strStatus;
        dr[1] = "03";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "April";
        dr[0] = strStatus;
        dr[1] = "04";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "May";
        dr[0] = strStatus;
        dr[1] = "05";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "June";
        dr[0] = strStatus;
        dr[1] = "06";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "July";
        dr[0] = strStatus;
        dr[1] = "07";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "August";
        dr[0] = strStatus;
        dr[1] = "08";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "September";
        dr[0] = strStatus;
        dr[1] = "09";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "October";
        dr[0] = strStatus;
        dr[1] = "10";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "November";
        dr[0] = strStatus;
        dr[1] = "11";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        strStatus = "December";
        dr[0] = strStatus;
        dr[1] = "12";
        dt.Rows.Add(dr);

        ddltextmonth.DataValueField = "month_number";
        ddltextmonth.DataTextField = "month";
        ddltextmonth.DataSource = dt;
        ddltextmonth.DataBind();
        // Go to Current Month
        ddltextmonth.Items.FindByValue(DateTime.Now.ToString("MM")).Selected = true;
    }



    private void ddlMonth_SelectedIndexChanged(object sender, System.EventArgs e) 
    {
        SetCalendarDate();
    }
    
    private void ddlYear_SelectedIndexChanged(object sender, System.EventArgs e) 
    {
        SetCalendarDate();
    }


    void SetCalendarDate() 
    {
        DateTime dtNewDate;

        //dtNewDate = DateTime.Parse((Int16.Parse(ddltextmonth.SelectedItem.Text) + ("/1/" + Int16.Parse(ddlYear.SelectedItem.Text))));
        dtNewDate = DateTime.Parse((Int16.Parse(ddltextmonth.SelectedItem.Value) + ("/1/" + Int16.Parse(ddlYear.SelectedItem.Value))));
        calDate.TodaysDate = dtNewDate;
    }

 
    protected void Change_Date(object sender, System.EventArgs e) {
        //Get a ClientScriptManager reference from the Page class.
        //ClientScriptManager cs = Page.ClientScript;       // V2.0
        string strScript;

        strScript = ("<script>parent.document.getElementById(\'" 
                    + (control.Value + "\').value  = \'"));
        strScript = (strScript + calDate.SelectedDate.ToString("dd/MM/yyyy"));
        strScript = (strScript + ("\';parent.document.getElementById(\'" 
                    + (control.Value + "\').focus(); \'")));
        strScript += "\';savingit() ";
        strScript = (strScript + ("</" + "script>"));

        RegisterClientScriptBlock("anything", strScript);       // V1.1
        //cs.RegisterClientScriptBlock(this.GetType(), "anything", strScript, false);        // V2.0
    }



</Script> 



<HTML>
<HEAD>
<TITLE>Calendar &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</TITLE>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">

<Script LANGUAGE="JavaScript">
<!--

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//This Section is for keeping the Modal form focused all the time (ie MODAL)
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var wb;
var checkblur;
var checksaved;
function init()
{
  checkblur = "False";
  //Must focus on a form element initially
  document.getElementById('tempinit').focus();   //Added field for POP-UP only

  if(navigator.appName == "Microsoft Internet Explorer")
   {
     elem=document.forms[0].elements;
     for(var i=0;i<elem.length;i++){
      elem[i].onfocus = function(){clearTimeout(wb);}
      elem[i].onblur = function(){wb=setTimeout('window.focus()',5)}
    }
    window.document.body.onblur = function(){checkonblur();}
   }
  else
   {
       elem=document.forms[0].elements;
       for(var i=0;i<elem.length;i++){
        elem[i].onfocus = function(){clearTimeout(wb);}
        elem[i].onblur = function(){wb=setTimeout('window.focus()',100)}
       }
       
   }

}


function checkonblur()
{
  if (checkblur == "False")
  {
       if(navigator.appName == "Microsoft Internet Explorer")
      {
        wb=setTimeout('window.focus()',50);
      }
      else
      {
       wb=setTimeout('window.focus()',100);
      }
  }

}


//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//END of  Section for keeping the form focused all the time.
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------




//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function setFocus()
{
     //alert("in setfocus");
     checksaved = "False";
     //init();
}


function setPostBack()
{
     //alert("in setPostBack");
     if (checksaved == "True")
     {
        //nothing
     }
     else
     {
      //init();
     }
     //Next line sets overlay PNG image to visible again, on the Opening window
     //window.opener.location = "javascript:KeepFocusClick();"
}



function savingit() 
{
  //alert("in savingit");
  checksaved = "True";   //new code
  //window.opener.SaveClick('refresh');    //only works for IE
  //Can change refresh to byitself, for when saving a field not in gridlist
  //window.opener.location = "javascript:SaveClick('refresh');"
  //window.opener.location = "javascript:SaveClick('byitself');"
  //self.close(); 
  parent.CloseCal();
}


function CloseCal() 
{
   parent.CloseCal();
}


//--> 
</Script>


</HEAD>

<body bgcolor="white" onload="<%=strPageload%>;">

<form id="form1" method="post" runat="server">

<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
<!-- Storing HIDDEN variables (MANDATORY) -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
<!-- next ASP.NET type hidden variables -->

<input id=control style="VISIBILITY: hidden" 
        type="text" runat="server" />

<!--Next variable is for Modal POP-UP only, so as to focus initially--> 
<asp:TextBox id="tempinit"
           style="BORDER-TOP: 1px solid black;
                      BORDER-BOTTOM: 1px solid black;
                      BORDER-LEFT: 1px solid black;
                      BACKGROUND-COLOR: white;
                      display:none;
                      BORDER-RIGHT: 1px solid black"
     readonly="false"
      tabIndex="-1"
      runat="server" 
     AutoCompleteType="Disabled">
</asp:TextBox>
             
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
<!-- END Storing HIDDEN variables (MANDATORY) -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->


 <!--div style="position: absolute; left: 304px; top: 1px; z-index: 100;">     
          <input id="Button345" type="button"  onclick="CloseCal()" style="text-align:center"
           value="Cancel" />
</div>-->   


        <!--Close Button using only Javascript-->
        <span style="position: absolute; visibility: visible; left: 260px; top: 1px; z-index: 100">
            <a href="javascript:CloseCal()">
                <img src="images/Close-image2.jpg" alt="Close" width="19" height="21" border="0">
            </a>
        </span>


<!--Start of Year-->            
<asp:Label id="Year1" 
             style="FONT-WEIGHT: bold; 
                    FONT-SIZE: 12px; 
                    Z-INDEX: 100; 
                    LEFT: 5px; 
                    COLOR: black; 
                    FONT-STYLE: normal; 
                    FONT-FAMILY: arial; 
                    display:none;
                    POSITION: absolute; 
                    TOP: 4px; 
                    BACKGROUND-COLOR: white" 
                    runat="server" height="21" width="100">
               Year:
</asp:Label>
    
<asp:DropDownList id="ddlYear" 
     style="POSITION: absolute; 
            LEFT: 36px;  
            TOP: 4px; 
            HEIGHT: 21px;
            WIDTH: 50px;
            BACKGROUND-COLOR: white;
            COLOR: navy;
            FONT-WEIGHT: bold;
            FONT-SIZE: 11px; 
            FONT-FAMILY: arial; 
            display:none;
            FONT-STYLE: normal; 
            Z-INDEX: 100"    
     tabIndex="1"
     runat="server"
     AutoPostBack="True"
     OnSelectedIndexChanged="ddlYear_SelectedIndexChanged">
</asp:DropDownList>


<!--Start of Month-->            
<asp:Label id="Month1" 
             style="FONT-WEIGHT: bold; 
                    FONT-SIZE: 12px; 
                    Z-INDEX: 100; 
                    LEFT: 98px; 
                    COLOR: black; 
                    FONT-STYLE: normal; 
                    FONT-FAMILY: arial; 
                    display:none;
                    POSITION: absolute; 
                    TOP: 4px; 
                    BACKGROUND-COLOR: white" 
                    runat="server" height="21" width="100">
               Month:
</asp:Label>
    
<asp:DropDownList id="ddltextmonth" 
     style="POSITION: absolute; 
            LEFT: 137px;  
            TOP: 4px; 
            HEIGHT: 21px;
            WIDTH: 89px;
            BACKGROUND-COLOR: white;
            COLOR: navy;
            FONT-WEIGHT: bold;
            FONT-SIZE: 11px; 
            display:none;
            FONT-FAMILY: arial; 
            FONT-STYLE: normal; 
            Z-INDEX: 100"    
     tabIndex="1"
     runat="server"
     AutoPostBack="True"
     OnSelectedIndexChanged="ddlMonth_SelectedIndexChanged">
</asp:DropDownList>




<!-- **********************************************************************************************************************************-->
<!-- START OF DATE Control on Form *****************************************************************************************-->
<!-- **********************************************************************************************************************************-->

<!--The next 3 controls make up the Calendar, which always will be displayed in the same place on the screen-->
<!--Please change the following code only:-  TextBox id, Calendar id, button id, onselectionchanged, onclick -->
<asp:TextBox id="caldatelabel" 
      style="POSITION: absolute; 
             LEFT: 5px;  
             TOP: 28px; 
             HEIGHT: 21px;
             WIDTH: 220px;
             BACKGROUND-COLOR: blue;
             COLOR: yellow;
             FONT-WEIGHT: bold;
             FONT-SIZE: 12px; 
             FONT-FAMILY: arial; 
             FONT-STYLE: normal; 
             TEXT-ALIGN: center; 
             display:none;
             BORDER-TOP: 1px solid black;
             BORDER-BOTTOM: 0px solid black;
             BORDER-LEFT: 1px solid black;
             BORDER-RIGHT: 1px solid black;
             Z-INDEX: 300"       
      readonly="True"
      Visible="true"
      runat="server">
</asp:TextBox>
<asp:Calendar id="calDate"
              style="border: 0px solid black; Z-INDEX: 300;
                     LEFT: 19px;
                     BACKGROUND-COLOR: white;
                     POSITION: absolute;
                     TOP: 9px; width: 239px;"
            runat="server"
            Height="200px"
            Width="220px"
            OnSelectionChanged="Change_Date"
            BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px" 
    DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" 
    ForeColor="#663399" ShowGridLines="True">

            <NextPrevStyle forecolor="#FFFFCC" Font-Size="9pt"></NextPrevStyle>
            <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
            <TitleStyle forecolor="White" backcolor="Blue"></TitleStyle>
            <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
            <SelectorStyle BackColor="#FFCC66" />
            <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
            <OtherMonthDayStyle forecolor="White"></OtherMonthDayStyle>
</asp:Calendar>

<!-- **********************************************************************************************************************************-->
<!-- END OF DATE Control on Form *****************************************************************************************-->
<!-- **********************************************************************************************************************************-->




<div id="nameList2">

</div>

</form>


</body>
</HTML>


